module SegDisplay(
    input clk,
    input [31:0] value,
    output reg [6:0] seg_led,   // 段选信号
    output reg [5:0] seg_sel    // 位选信号
);

    reg [3:0] digit; // 当前显示的数字
    reg [2:0] seg_cnt; // 计数器，用于轮流显示6位数码管

    initial begin
        seg_cnt = 3'b000; // 初始化计数器
    end

    always @(posedge clk) begin
        if (seg_cnt == 3'b001) // 当计数器达到 5 时重置
            seg_cnt <= 3'b000;
        else
            seg_cnt <= seg_cnt + 1;
    end

    always @(*) begin
        case (seg_cnt)
            3'b000: digit = value[3:0];
            3'b001: digit = value[7:4];
            3'b010: digit = value[11:8];
            3'b011: digit = value[15:12];
            3'b100: digit = value[19:16];
            3'b101: digit = value[23:20];
            default: digit = 4'h0;
        endcase

        case (digit)
            4'h0: seg_led = 7'b1111110; // 显示0
            4'h1: seg_led = 7'b0110000; // 显示1
            4'h2: seg_led = 7'b1101101; // 显示2
            4'h3: seg_led = 7'b1111001; // 显示3
            4'h4: seg_led = 7'b0110011; // 显示4
            4'h5: seg_led = 7'b1011011; // 显示5
            4'h6: seg_led = 7'b1011111; // 显示6
            4'h7: seg_led = 7'b1110000; // 显示7
            4'h8: seg_led = 7'b1111111; // 显示8
            4'h9: seg_led = 7'b1111011; // 显示9
            default: seg_led = 7'b1111111; // 显示空
        endcase
    end

    always @(*) begin
        case (seg_cnt)
            3'b000: seg_sel = 6'b000001;
            3'b001: seg_sel = 6'b000010;
            3'b010: seg_sel = 6'b000100;
            3'b011: seg_sel = 6'b001000;
            3'b100: seg_sel = 6'b010000;
            3'b101: seg_sel = 6'b100000;
            default: seg_sel = 6'b000000;
        endcase
    end

    initial begin
        $monitor($time, " SegDisplay: clk=%b, seg_cnt=%b, digit=%h, seg_led=%b, seg_sel=%b", clk, seg_cnt, digit, seg_led, seg_sel);
    end
endmodule
